﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CommodityManage.aspx.cs" Inherits="GS_OM.Pages.CommodityManage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../files/css/bootstrap.min.css" rel="stylesheet" />
    <link href="../files/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
    <link href="../files/css/font-awesome.css" rel="stylesheet" />
    <link href="../files/css/main.css" rel="stylesheet" />

</head>
<body class="tran_lg">
    <div class="_info">
        <div class="_title">
            <img src="../files/img/small_img/nav_img/commodity_management.png" /><span>商场管理</span>
        </div>
        <table class="cm_dateBtn" width="100%">
            <tr>
                <td>
                    <div class="control-group">
                        <div id="start_date" class="controls input-append date form_datetime" data-date="" data-date-format="yyyy-mm-dd" data-link-field="dtp_input1">
                            <input size="16" type="text" value="" readonly>
                            <span class="add-on"><i class="icon-th datepng"></i></span>
                        </div>
                        <input type="hidden" id="dtp_input1" value="" /><br />
                    </div>
                </td>
                <td valign="top">
                    <div class="control-group ">
                        <div class="controls input-append date">
                            <input size="16" type="text" value="" id="find_info" />
                            <span class="add-on"><i class="icon-th selectpng" onclick="findTab()"></i></span>
                        </div>
                    </div>
                </td>
                <td>
                    <div class="control-group">
                        <div id="end_date" class="controls input-append date form_datetime" data-date="" data-date-format="yyyy-mm-dd" data-link-field="dtp_input2">
                            <input size="16" type="text" value="" readonly>
                            <span class="add-on"><i class="icon-th datepng"></i></span>
                        </div>
                        <input type="hidden" id="dtp_input2" value="" /><br />
                    </div>
                </td>
            </tr>
        </table>
        <div class="tabbable tabs-right">
            <ul class="nav nav-tabs" id="myTabright">
                <li class="active"><a data-toggle="tab" href="#home-right">全部</a></li>
                <li><a data-toggle="tab" href="#profile-right">审核</a></li>
                <li><a data-toggle="tab" href="#dropdown3-right">待审核</a></li>
                <li><a data-toggle="tab" href="#dropdown4-right">审核未通过</a></li>
                <li><a data-toggle="tab" href="#dropdown5-right">储存</a></li>
            </ul>
            <div class="tab-content">
                <div id="home-right" class="tab-pane fade in active">
                    <table id="all_manage">
                        <thead>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <div class="widget-content table_btn" id="all_holder"></div>
                </div>
                <div id="profile-right" class="tab-pane fade ">
                    <table id="yes_manage">
                        <thead>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <div class="widget-content table_btn" id="yes_holder"></div>
                </div>
                <div id="dropdown3-right" class="tab-pane fade">
                    <table id="no_manage">
                        <thead>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <div class="widget-content table_btn" id="no_holder"></div>
                </div>
                <div id="dropdown4-right" class="tab-pane fade">
                    <table id="rejected_manage">
                        <thead>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <div class="widget-content table_btn" id="rejected_holder"></div>
                </div>
                <div id="dropdown5-right" class="tab-pane fade">
                    <table id="saved_manage">
                        <thead>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <div class="widget-content table_btn" id="saved_holder"></div>
                </div>
            </div>
        </div>
    </div>
    <script src="../files/javascript/jquery-1.10.2.min.js"></script>
    <script src="../files/javascript/bootstrap.min.js"></script>
    <script src="../files/javascript/bootstrap-datetimepicker.min.js"></script>
    <script src="../files/js/grid.locale-cn.js"></script>
    <script src="../files/js/jquery.jqGrid.min.js"></script>
    <script src="../files/js/jPages.js"></script>
    <script src="../files/js/main.js"></script>
    <script>
        var obj = null;
        var startDate = null;
        var endDate = null;
        $(document).ready(function () {
            $.fn.datetimepicker.dates['zh-CN'] = {
                days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
                daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
                daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
                months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                today: "今日",
                suffix: [],
                meridiem: ["上午", "下午"],
                format: "yyyy-mm-dd" /*控制显示格式,默认为空，显示小时分钟*/
            };

            $('.form_datetime').datetimepicker({
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: true,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            });

            $('#start_date').datetimepicker().on('changeDate', function (ev) {
                loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: block;} .tab-content > .active, .pill-content > .active {display: block;");    //设置页面table显示隐藏样式
                $("#all_manage>tbody").html("");
                $("#yes_manage>tbody").html("");
                $("#no_manage>tbody").html("");
                $("#rejected_manage>tbody").html("");
                $("#saved_manage>tbody").html("");
                for (var i = obj.length - 1; i >= 0; i--) {
                    startDate = obj[i].Push_Start;
                    var date = startDate.substr(startDate.lastIndexOf('(') + 1, startDate.lastIndexOf(')') - startDate.lastIndexOf('(') - 1);

                    if (parseInt(date) > parseInt(ev.date.valueOf())) {
                        bindPage(obj[i]);
                    }
                }
                bindPaging(); //绑定分页按钮
                loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: none;} .tab-content > .active, .pill-content > .active {display: block;");    //设置页面table显示隐藏样式
            });
            $('#end_date').datetimepicker().on('changeDate', function (ev) {
                loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: block;} .tab-content > .active, .pill-content > .active {display: block;");    //设置页面table显示隐藏样式
                $("#all_manage>tbody").html("");
                $("#yes_manage>tbody").html("");
                $("#no_manage>tbody").html("");
                $("#rejected_manage>tbody").html("");
                $("#saved_manage>tbody").html("");
                for (var i = obj.length - 1; i >= 0; i--) {
                    endDate = (obj[i].Push_Start);
                    var date = endDate.substr(endDate.lastIndexOf('(') + 1, endDate.lastIndexOf(')') - endDate.lastIndexOf('(') - 1);
                    if (parseInt(date) <= parseInt(ev.date.valueOf())) {
                        bindPage(obj[i]);
                    }
                }
                bindPaging(); //绑定分页按钮
                loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: none;} .tab-content > .active, .pill-content > .active {display: block;");    //设置页面table显示隐藏样式
            });


            $.ajax({
                type: "post",
                datatype: "json",
                url: "../SMHandler/PushTabHandler.ashx",
                success: function (data) {
                    obj = JSON.parse(data);
                    $("#all_manage>thead").append("<tr><th>#</th><th>图片</th><th>信息</th><th>日期</th><th>类型</th><th></th></tr>");
                    $("#yes_manage>thead").append("<tr><th>#</th><th>图片</th><th>信息</th><th>日期</th><th>类型</th><th></th></tr>");
                    $("#no_manage>thead").append("<tr><th>#</th><th>图片</th><th>信息</th><th>日期</th><th>类型</th><th></th></tr>");
                    $("#rejected_manage>thead").append(" <tr><th>#</th><th>图片</th><th>信息</th><th>日期</th><th>类型</th><th></th></tr>");
                    $("#saved_manage>thead").append(" <tr><th>#</th><th>图片</th><th>信息</th><th>日期</th><th>类型</th><th></th></tr>");
                    for (var i = obj.length - 1; i >= 0; i--) {
                        bindPage(obj[i]);
                    }
                    bindPaging();
                    loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: none;} .tab-content > .active, .pill-content > .active {display: block;");
                    window.parent.iFrameHeight();
                },
                error: function () {
                    loadCss(".tab-content > .tab-pane, .pill-content > .pill-pane {display: none;} .tab-content > .active, .pill-content > .active {display: block;");
                }
            });

        });

        function findTab() {
            //var find_info = $("#find_info").val();
            //loadCss();    //设置页面table显示隐藏样式
            //$("#all_manage>tbody").html("");
            //$("#yes_manage>tbody").html("");
            //$("#no_manage>tbody").html("");
            //$("#rejected_manage>tbody").html("");
            //$("#saved_manage>tbody").html("");
            //for (var i = obj.length - 1; i >= 0; i--) {

            //}
            //bindPaging(); //绑定分页按钮
            //loadCss();    //设置页面table显示隐藏样式
        }

        function showBack(id) {
            for (var i = 0; i < $("#" + id + ">tr").length; i++) {
                if (i % 2 == 0)
                    $("#" + id + ">tr").eq(i).addClass("tab_odd_line");
                else
                    $("#" + id + ">tr").eq(i).addClass("tab_even_line");
                if ((i + 1) % 4 == 0)
                    $("#" + id + ">tr").eq(i).addClass("end_tr");
                else
                    $("#" + id + ">tr").last().addClass("end_tr");
            }
        }

        function loadCss(css) {
            var fileref = document.createElement("style")
            fileref.innerHTML = css;
            document.head.appendChild(fileref);
        } 

        function writeTab(ID, obj, isUpdate) {
            var date = new Date(parseInt(obj.Push_Start.replace(/\/Date\((-?\d+)\)\//, '$1')));
            var time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            $("#" + ID).append('<tr><td class="tab_Num">' + obj.Push_ID + '</td><td><img src="' + obj.Push_Res + '" width="128px" height="128px"  style="padding-top:4px;"/></td><td>' + obj.Push_Type + '<br />512*512</td><td>' + time + '</td><td>' + obj.Push_Approval + '</td><td><table class="tab_edit center"><tr>' + (isUpdate == "isUpdate" ? '<td><a href="javascript:iFrameSrc(\'ProductLaunch.aspx?type=updatePro&id=' + obj.Push_ID + '\')"><img src="../files/img/small_img/edit.png" width="26px" height="26px" /></a> </td><td class="tab_edit_line"><line></line></td>' : '') + '<td><a href="javascript:delproduct(' + obj.Push_ID + ')"><img src="../files/img/small_img/delete.png" width="26px" height="26px" /></a></td></tr></table></td></tr>');
        }
        function jPages(btnID, ID) {
            $(btnID).jPages({
                containerID: ID,
                previous: "上一页",
                next: "下一页",
                perPage: 4,
                delay: 4
            });
        }

        function bindPaging() {
            jPages("#all_holder", "all_manage>tbody");
            jPages("#yes_holder", "yes_manage>tbody");
            jPages("#no_holder", "no_manage>tbody");
            jPages("#rejected_holder", "rejected_manage>tbody");
            jPages("#saved_holder", "saved_manage>tbody");

            showBack("all_manage>tbody");
            showBack("yes_manage>tbody");
            showBack("no_manage>tbody");
            showBack("rejected_manage>tbody");
            showBack("saved_manage>tbody");
        }
        function bindPage(obj) {
            writeTab("all_manage>tbody", obj);
            switch (obj.Push_Approval) {
                case "已审核":
                    writeTab("yes_manage>tbody", obj, "");
                    break;
                case "待审核":
                    writeTab("no_manage>tbody", obj, "");
                    break;
                case "审核未通过":
                    writeTab("rejected_manage>tbody", obj, "isUpdate");
                    break;
                case "储存":
                    writeTab("saved_manage>tbody", obj, "isUpdate");
                    break;
            }
        }

        function delproduct(id) {
            if (confirm("确定删除吗？")) {
                $.ajax({
                    type: "get",
                    data: "id=" + id,
                    datatype: "text",
                    url: "../SMHandler/UpdatePushActiveStatusHandler.ashx",
                    success: function (data) {
                        if (data == "true") window.location.href = window.location.href; else alert("删除失败！");
                    }
                });
            }
        }
    </script>

</body>
</html>
